/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     2015/4/21 20:51:09                           */
/*==============================================================*/
create database CourseDB
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TComment')
            and   type = 'U')
   drop table TComment
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TMenu')
            and   type = 'U')
   drop table TMenu
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TModule')
            and   type = 'U')
   drop table TModule
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TNotice')
            and   type = 'U')
   drop table TNotice
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TRecommend')
            and   type = 'U')
   drop table TRecommend
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TResource')
            and   type = 'U')
   drop table TResource
go

if exists (select 1
            from  sysobjects
           where  id = object_id('TUser')
            and   type = 'U')
   drop table TUser
go

/*==============================================================*/
/* Table: TComment                                              */
/*==============================================================*/
create table TComment (
   Code                 int                  not null,
   PId                  int                  not null,
   Content              varchar(500)         not null,
   CreateTime           datetime             not null,
   Nick                 varchar(20)          not null,
   IP                   varchar(15)          null,
   Email                varchar(50)          null,
   QQ                   varchar(15)          null
)
go

/*==============================================================*/
/* Table: TMenu                                                 */
/*==============================================================*/
create table TMenu (
   Code                 int                  identity,
   Name                 varchar(20)          not null,
   "Order"              int                  not null default 100,
   Url                  varchar(100)         not null,
   TargetBlank          bit                  not null default 0,
   constraint PK_TMENU primary key (Code)
)
go

/*==============================================================*/
/* Table: TModule                                               */
/*==============================================================*/
create table TModule (
   Code                 int                  identity,
   Name                 varchar(50)          not null,
   CreateTime           datetime             null default getdate(),
   UpdateTime           datetime             null default getdate(),
   constraint PK_TMODULE primary key (Code)
)
go

/*==============================================================*/
/* Table: TNotice                                               */
/*==============================================================*/
create table TNotice (
   Code                 int                  identity,
   Content              varchar(500)         not null,
   CreateTime           datetime             not null default getdate(),
   UpdateTime           datetime             not null default getdate(),
   UpdateUserId         int                  not null,
   IsActive             bit                  not null default 0,
   constraint PK_TNOTICE primary key (Code)
)
go

/*==============================================================*/
/* Table: TRecommend                                            */
/*==============================================================*/
create table TRecommend (
   Code                 int                  identity,
   Name                 varchar(20)          not null,
   Url                  varchar(100)         null,
   Position             int                  not null,
   Image                varchar(100)         not null,
   constraint PK_TRECOMMEND primary key (Code)
)
go

/*==============================================================*/
/* Table: TResource                                             */
/*==============================================================*/
create table TResource (
   Code                 int                  identity,
   ModuleId             int                  not null,
   UserId               int                  not null,
   Title                varchar(20)          not null,
   Content              varchar(max)         not null,
   CreateTime           datetime             null default getdate(),
   UpdateTime           datetime             null,
   IsRecommended        bit                  null default 0,
   constraint PK_TRESOURCE primary key (Code)
)
go

/*==============================================================*/
/* Table: TUser                                                 */
/*==============================================================*/
create table TUser (
   Code                 int                  identity,
   Name                 varchar(20)          not null,
   Password             varchar(20)          not null,
   RealName             varchar(20)          not null,
   State                int                  not null,
   CreateTime           datetime             not null default getdate(),
   CreateUserId         int                  not null default 0,
   constraint PK_TUSER primary key (Code)
)
go

